﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PursuitDrift.GameObjects.PhysicObjects.Cars;

namespace CarCreator
{
    public partial class MainForm : Form
    {
        private CarInformation _carInfo;

        public MainForm()
        {
            InitializeComponent();

            _carInfo = new CarInformation();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                CarInformation.Serialize(saveFileDialog.FileName, _carInfo);
            }
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = MessageBox.Show("Wirklich beenden?\nUngespeicherte Daten gehen verloren.", "CarCreator beenden",
                           MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.No)
            {
                e.Cancel = true;
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            propertyGrid.SelectedObject = _carInfo;
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                _carInfo = CarInformation.Deserialize(openFileDialog.FileName);
                propertyGrid.SelectedObject = _carInfo;
            }
        }
    }
}
